package Problem2;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Text {
    public static void main(String[] args) {
        List<User> userLists = new ArrayList<>();

        String userStrs = "10001:张三:男:1990-01-01#" +
                "10002:李四:女:1989-01-09#" +
                "10003:王五:男:1999-09-09#" +
                "10004:刘备:男:1899-01-01#" +
                "10005:孙悟空:男:1900-01-01#" +
                "10006:张三:女:1999-01-01#" +
                "10007:刘备:女:1999-01-01#" +
                "10008:张三:女:2003-07-01#" +
                "10009:猪八戒:男:1900-01-01#";

        String[] userInformation = userStrs.split("#");
        for (int i = 0; i < userInformation.length; i++) {
            String[] userSpilt = userInformation[i].split(":");
            String idString = userSpilt[0];
            long id = Long.valueOf(idString);
            String name = userSpilt[1];
            String gender = userSpilt[2];
            String birthdayString = userSpilt[3];
            LocalDate birthday = LocalDate.parse(birthdayString);
            User user = new User(id,gender,birthday,name);
            userLists.add(user);
        }
        System.out.println(userLists);

        //遍历集合中的每个名字出现的次数
        Map<String,Integer> map = new HashMap<>();
        for (User userList : userLists) {
            if (map.containsKey(userList.getName())){
                map.put(userList.getName(),map.get(userList.getName())+1);
            }else {
                map.put(userList.getName(),1);
            }
        }
        //遍历打印map集合
        map.forEach((k,v)-> System.out.println(k+" : "+v));
    }
}
